#####################################
# REPLICATE CROES AND TAMMES (2004) #
#####################################

# Author: Kasia Nalewajko
# First version: 29 November 2023
# Replicated: 13 June 2024


rm(list = ls())

# LOAD PACKAGES -----------------------------------------------------------

if (!require("dplyr")) install.packages("dplyr")
if (!require("readxl")) install.packages("readxl")
if (!require("estimatr")) install.packages("estimatr")
if (!require("modelsummary")) install.packages("modelsummary")

# LOAD DATA ---------------------------------------------------------------

flap <- read_excel("./00 SUBMITTED/00 APSR final/04 replication_files/01 data/Flap et al table.xlsx")

# CLEAN ----

flap$resistance_fighters_1000 <- flap$resistance_fighters*1000/flap$pop1941

# THEIR MODEL -----

ct2004_weighted <- flap %>% 
  lm(formula = jews_victims_prop ~ resistance_fighters_1000, weights = jews1942)
summary(ct2004_weighted)

# MY MODELS ----

overijssel <- flap %>% 
  lm(formula = log(jews_victims_prop+1) ~ log(resistance_fighters+1) + log(jews1942+1) + log(pop1941+1))
summary(overijssel)

twente <- flap %>% 
  filter(twente == 1) %>% 
  lm(formula = log(jews_victims_prop+1) ~ log(resistance_fighters+1)  + log(jews1942+1) + log(pop1941+1))
summary(twente)

no_twente <- flap %>% 
  filter(twente == 0) %>% 
  lm(formula = log(jews_victims_prop+1) ~ log(resistance_fighters+1) + log(jews1942+1) + log(pop1941+1))
summary(no_twente)

# EXPORT ----

msummary(list(
  'Identical replication' = ct2004_weighted,
  'Whole Overjissel' = overijssel,
  'Only Twente' = twente,
  'No Twente' = no_twente
),
stars = c('*' = .1, '**' = .05, '***' = .01),
gof_omit = "AIC|BIC|RMSE|R2 Within|R2 Within Adj.",
output = "latex",
coef_rename = c("resistance_fighters_1000" = "Resistance fighters per 1,000 inhab.",
                "log(resistance_fighters + 1)" = "Resistance fighters (logged)",
                "log(jews1942 + 1)" = "1942 Jewish population (logged)",
                "log(pop1941 + 1)" = "1941 population (logged)"
),
title = "Replication of Croes and Tammes (2004)"
)
